﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;

namespace Infrastructure.Utility.Core.CommonUtility
{
    public static class AmountUtility
    {
        /// <summary>
        /// 金额（分）格式化（并转换单位为元）
        /// </summary>
        /// <param name="amount"></param>
        /// <returns></returns>
        public static string AmountFenToYuanFormat(this long amount, bool hasPre = true)
        {
            var amountStr = (hasPre ? "¥" : "") + string.Format("{0:N2}", (amount * 0.01));
            return amountStr;
        }

        /// <summary>
        /// 金额（分）格式化（并转换单位为元）
        /// </summary>
        /// <param name="amount"></param>
        /// <returns></returns>
        public static string AmountFenToYuanFormat(this long? amount)
        {
            if (amount == null)
            {
                return string.Empty;
            }

            var amountStr = string.Format("¥{0:N2}", (amount * 0.01));
            return amountStr;
        }
    }
}